from collections import defaultdict
from typing import Callable


class EventBus:
    topic_subscribers = defaultdict(set)

    @classmethod
    def register(cls, topic: str, function: Callable):
        cls.topic_subscribers[topic].add(function)

    @classmethod
    def publish(cls, topic: str, *args, **kwargs):
        for function in cls.topic_subscribers[topic]:
            function(*args, **kwargs)
